﻿// testfunction.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//

#include <iostream>
using namespace std;

bool View(int index)
{
    cout << "call View(" << index << ")" << endl;
    return true;
}

void SetSize(int w, int h)
{
    w += 1;
    cout << "SetSize" << endl;
    cout << w << ":" << h << endl;
    cout << (long long)&w << ":" << (long long)&h << endl;
    cout << "------SetSize" << endl;
}
int gcount = 0;
static int scount = 0;

int TestVer(int x, int y)
{
    int tmp = x + y;
    // 局部静态变量，只在第一次运行代码申请空间
    // 声明周期
    // c++11 以后，线程安全
    static int count = 0;
    gcount++;
    scount++;
    count++;
    cout << "gcount = " << gcount << endl;
    cout << "scount = " << scount << endl;
    cout << "count = " << count << endl;
    return tmp;
}

void TestParaPtr(const int* x, const int* y)
{
    cout << "TestParaPtr" << *x << " " << *y << endl;
    cout << x << ":" << y << endl;
}

void TestParaRef(const int& x, const int& y)
{
    cout << "TestParaRef" << x << " " << y << endl;
    cout << &x << ":" << &y << endl;
}

//void GetPosPtr(int* x, int* y)
//{
//    *x = 800;
//    *y = 600;
//}
//
//void GetPosRef(int& x, int& y)
//{
//    x = 1800;
//    y = 1600;
//}

int* GetPosPtr()
{
    static int pos{ 0 };
    cout << "GetPosPtr pos: " << pos << endl;
    return &pos;
}

int& GetPosRef()
{
    static int pos{ 0 };
    cout << "GetPosRef pos: " << pos << endl;
    return pos;
}

int main()
{
    {
        auto res = GetPosPtr();
        (*res) += 10;
        GetPosPtr();

        auto &r2 = GetPosRef();
        r2 += 20;
        GetPosRef();
    }
    {
        int x{ 99 };
        int y{ 88 };
        //TestParaPtr(&x, &y);
        //TestParaRef(x, y);

        //GetPosPtr(&x, &y);
        //cout << "x: " << x << " y: " << y << endl;

        //GetPosRef(x, y);
        //cout << "x: " << x << " y: " << y << endl;

    }
    {
        int w = 1920;
        int h = 1080;
        //cout << "main" << endl;
        //cout << (long long)&w << ":" << (long long)&h << endl;
        //SetSize(w, h);
        //cout << "main" << endl;
        //cout << w << ":" << h << endl;
        //TestVer(100, 200);
        //TestVer(200, 300);
        //auto re = TestVer(300, 400);
        //cout << "auto re = TestVer(300, 400); auto re = " << re << endl;

        int x{ 10 };
        //cout << "x = " << x << endl;
        //cout << "&x = " << &x << endl;
        int* p = &x;
        *p = 11;
        //cout << "*p = " << *p << endl;
        //cout << "x = " << x << endl;
        //cout << "p = " << p << endl;
        //cout << "&p = " << &p << endl;
        //(*p)++;
        //cout << "x = " << x << endl;

        int& ref = x;
        //cout << "ref = " << ref << endl;
        //cout << "&ref = " << &ref << endl;

        ref++;
        //cout << "x = " << x << endl;
        return 0;
    }
}

// 运行程序: Ctrl + F5 或调试 >“开始执行(不调试)”菜单
// 调试程序: F5 或调试 >“开始调试”菜单

// 入门使用技巧: 
//   1. 使用解决方案资源管理器窗口添加/管理文件
//   2. 使用团队资源管理器窗口连接到源代码管理
//   3. 使用输出窗口查看生成输出和其他消息
//   4. 使用错误列表窗口查看错误
//   5. 转到“项目”>“添加新项”以创建新的代码文件，或转到“项目”>“添加现有项”以将现有代码文件添加到项目
//   6. 将来，若要再次打开此项目，请转到“文件”>“打开”>“项目”并选择 .sln 文件
